VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} formArrayBatch 
   Caption         =   "Array Batch Process"
   ClientHeight    =   2640
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9750
   OleObjectBlob   =   "formArrayBatch.frx":0000
   ShowModal       =   0   'False
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "formArrayBatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Project Name:  Array
'Host Name:     Array.formArrayBatch
'Date:
'Version:
'Revised by:    Joseph Weir

' Cafe ArrayBatch from FXI using Package.SendToScreen, Cafe.Screen.Process and Timer.
'
' 2004-08-25, JFW, Initial version.
' 2005-12-09, JFW, Code review.

Option Explicit

Dim m_fcilPackageXML As FedExCanada.PackageXML

Dim m_objFCIL_TD As FedExCanada.TD

Dim m_objExcelBatch As classExcelBatch

Dim m_objPackageTest As Package
Dim m_objPackage As Object
Dim m_objShipment As Shipment

Dim m_objXML As Object

Dim WithEvents timerTDB As Timer
Attribute timerTDB.VB_VarHelpID = -1
Dim WithEvents timerTest As Timer
Attribute timerTest.VB_VarHelpID = -1

Dim m_lngShipmentCount As Long
Dim m_strFirstTrackingNumber As String    ' First shipment of batch
Dim m_strSecondTrackingNumber As String   ' First shipment of TD MPS
'
Dim m_boolAfterShipment As Boolean
'


Private Function BatchShipNext() As Boolean

    On Error GoTo ErrorExit
    
    Dim i As Long
    Dim j As Long
    Dim strError As String         ' from passport
    Dim strTrackingNumber As String         ' from passport
    Dim strTrackingNumber1 As String        ' master
    Dim strTrackingNumberAll As String      ' all strung out
    Dim strFreightCharge As String
    Dim lngPackageCount As Long
    Dim tblShipmentLookUp As Table
    
    Dim strTransIn As String
    Dim strTransOut As String
        
    m_lngShipmentCount = m_lngShipmentCount + 1
    
    Debug.Print Now & ", BatchShipNext, count " & m_lngShipmentCount
    
    If m_lngShipmentCount = 1 _
    And m_objExcelBatch.PackageCount > 1 _
    And Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
        ' This is now the second piece of the first shipment of an MPS TD batch
        lngPackageCount = lngPackageCount + 1
    Else
        
        If m_fcilPackageXML Is Nothing Then
            Set m_fcilPackageXML = New PackageXML
        End If
        Set m_objXML = m_fcilPackageXML.AfterShipXMLRequest(m_strFirstTrackingNumber)
        ' Need an empty Shipment object
        Set m_objShipment = New Shipment
        ' Create a package from an XML document
        Set m_objPackage = m_fcilPackageXML.ShipXMLMPS(m_objShipment, m_objXML)
        
        ' Logfile "ArrayBatch.BatchShipNext, trk " & m_strFirstTrackingNumber & ", MPS count " & m_objShipment.MPS.Packages.Count
        
        If Not m_objExcelBatch.ShipNext(m_objShipment) Then

            ' Logfile "ArrayBatch.BatchShipNext, exit false"
            
            BatchShipNext = False
            Exit Function
        End If
    End If
    
    Me.textStatus = "Processing " & m_objExcelBatch.Count & " of " & m_objExcelBatch.CountTotal & ", " & m_objExcelBatch.CountError & " in error." _
        & vbCrLf & m_objShipment.Recipient.Company & ", " & m_objShipment.Recipient.City & "."
    
    If Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
        Set m_objPackage = m_objShipment.Package
        m_objPackage.Intl.IncludeTD = True
    End If
    
    If Me.checkDocs And m_objShipment.Recipient.Country <> "CA" Then
        If m_objShipment.MPS.Packages.Count >= 1 Then
            m_objShipment.MPS.International.Commodities.Clear
            m_objShipment.MPS.International.Docs.Clear
            With m_objShipment.MPS.International.Docs.Add("1")
                .CountryOfMfg = "CA"
                .DocumentCode = fsmBusinessCorrespondence
                .Description = "Business Correspondence"
            End With
        Else
            Set m_objPackage = m_objShipment.Package
            m_objPackage.Intl.Commodities.Clear
            m_objPackage.Intl.Docs.Clear
            With m_objPackage.Intl.Docs.Add("1")
                .CountryOfMfg = "CA"
                .DocumentCode = fsmBusinessCorrespondence
                .Description = "Business Correspondence"
            End With
        End If
    End If
    
    Do
    
        ' Second or later package, TD MPS
        If lngPackageCount > 0 _
        And m_objExcelBatch.PackageCount > 1 _
        And Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
            
            If m_objExcelBatch.ShipWeight(lngPackageCount) <> "" Then
                m_objPackage.Weight = m_objExcelBatch.ShipWeight(lngPackageCount)
            End If
            
            If Not m_objExcelBatch.ShipDims(lngPackageCount) Is Nothing Then
                m_objPackage.Dimensions.Length = m_objExcelBatch.ShipDims(lngPackageCount).Item(1)
                m_objPackage.Dimensions.Width = m_objExcelBatch.ShipDims(lngPackageCount).Item(2)
                m_objPackage.Dimensions.Height = m_objExcelBatch.ShipDims(lngPackageCount).Item(3)
            End If
            
            ' Logfile "BatchShipNext, 1, dims length " & m_objPackage.Dimensions.Length
            
            With m_objPackage.Intl.Commodities
                .Clear
                With .Add("1")
                    .CountryOfMfg = "CA"
                    .Description = "Package " & CStr(lngPackageCount + 1) & " of " & CStr(m_objExcelBatch.PackageCount) _
                                & ", master tracking number " & m_strSecondTrackingNumber
                    .UnitOfMeasure = "EA"
                    .UnitQuantity = 1
                    .UnitValue = 0.000001
                End With
            End With
            
            ' Logfile "BatchShipNext, 1a, MPS commodity, dims length " & m_objPackage.Dimensions.Length

        End If

        ' Loop for each package in PackageCount
        If Me.checkTD And m_objExcelBatch.IncludeTD Then
            If m_objFCIL_TD Is Nothing Then
                Set m_objFCIL_TD = New FedExCanada.TD
            End If
            If m_objFCIL_TD.UseCurrentMaster <> "" Then
            
                ' 2011-07-07, JFW, Allow Future date.
                m_objShipment.Package.SpecialServices.FutureShipment.ShipDate = m_objFCIL_TD.MasterShipmentPickupDate
                
                ' 2011-01-31, JFW, Get CI flag from master.
                m_objShipment.Package.Intl.IncludeCommercialInvoice = m_objFCIL_TD.MasterShipmentCI
                '
                On Error GoTo ErrorFCILReturnAddress
                With m_objFCIL_TD.MasterShipmentReturnAddress
                    m_objShipment.Package.ReturnAddress.Address1 = .Item("Address1").Item("Value")
                    m_objShipment.Package.ReturnAddress.Address2 = .Item("Address2").Item("Value")
                    m_objShipment.Package.ReturnAddress.City = .Item("City").Item("Value")
                    m_objShipment.Package.ReturnAddress.Company = .Item("Company").Item("Value")
                    m_objShipment.Package.ReturnAddress.Contact = .Item("Contact").Item("Value")
                    m_objShipment.Package.ReturnAddress.Phone = .Item("Phone").Item("Value")
                    m_objShipment.Package.ReturnAddress.State = .Item("State").Item("Value")
                    m_objShipment.Package.ReturnAddress.Zip = .Item("Zip").Item("Value")
                End With
                
                ' Logfile "ArrayBatch, BatchShipNext, b4 process, TD, Intl TD Process"

                ' Logfile "BatchShipNext, 1b, processing, dims length " & m_objPackage.Dimensions.Length

                On Error GoTo ProcessContinue
                m_objShipment.Package.Process
            
            Else
                Err.Raise 12345, "FCIL.UseCurrentMaster", "Current TD Master shipment cannot be determined.  See the TD Dashboard."
            End If
            
        Else
            ' ' Logfile "IOR", strTransIn
            Call m_objExcelBatch.SoldTo(m_objShipment)
            
            If Me.checkDocs Then
                ' Logfile "ArrayBatch, BatchShipNext, MPS, Intl Docs"
                With m_objShipment.Package.Intl.Docs.Add(1)
                    .CountryOfMfg = "CA"
                    .Description = "Business Correspondence"
                End With
            Else
                If m_objShipment.MPS.Packages.Count > 0 Then
                    If m_objShipment.MPS.Recipient.Country <> "CA" Then
                        With m_objShipment.MPS.International
                            .PackageType = fsmFedEx_Intl_Box
                            
                            ' Logfile "ArrayBatch, BatchShipNext, MPS, Intl UploadTrade"
                            
                            .IncludeTD = False
                            .UploadTradeDocumentsFlag = True
                            .IncludeCommercialInvoice = True
                            .CommercialInvoice.Copies = 0
                            If .Commodities.Count <= 0 Then
                                With .CommercialInvoice
                                    .InvoiceType = fsmCommercialInvoice
                                    .Copies = 0
                                    .InvoicePurpose = fsmSold
                                End With
                            Else
                                With .CommercialInvoice
                                    .InvoiceType = fsmMyOwnCommercialInvoice
                                    .Copies = 0
                                    .InvoicePurpose = fsmSold
                                    .InvoicePath = Cafe4.CreateShipmentCI(m_objShipment)
                                End With
                            End If
                        End With
                    End If
                Else
                    If m_objShipment.Recipient.Country <> "CA" Then
                        With m_objShipment.Package.Intl
                            .PackageType = fsmFedEx_Intl_Box
                            
                            ' Logfile "ArrayBatch, BatchShipNext, 1 pc, Intl TradeDocs"
    
                            .IncludeTD = False
                            .UploadTradeDocumentsFlag = True
                            .IncludeCommercialInvoice = True
                            .CommercialInvoice.Copies = 0
                            If .Commodities.Count <= 0 Then
                                With .CommercialInvoice
                                    .InvoiceType = fsmCommercialInvoice
                                    .Copies = 0
                                    .InvoicePurpose = fsmSold
                                End With
                            ElseIf False Then
                                With .CommercialInvoice
                                    .InvoiceType = fsmCommercialInvoice
                                    .Copies = 1
                                    .InvoicePurpose = fsmSold
                                End With
                            Else
                                With .CommercialInvoice
                                    .InvoiceType = fsmMyOwnCommercialInvoice
                                    .Copies = 0
                                    .InvoicePurpose = fsmSold
                                    .InvoicePath = Cafe4.CreatePackageCI(m_objShipment.Package)
                                End With
                            End If
                        End With
                    End If
                End If
            End If
            
            On Error GoTo ProcessContinue
            If m_objShipment.MPS.Packages.Count > 0 Then
                
                ' Logfile "ArrayBatch, BatchShipNext, b4 process, MPS, Process"
                
                m_objShipment.MPS.Process
            Else
                
                ' Logfile "ArrayBatch, BatchShipNext, b4 process, 1 pc, Process"
                
                m_objShipment.Package.Process
            End If
            
        End If
        
    Debug.Print Now & " BatchShipNext, processed " & m_lngShipmentCount
        
ProcessContinue:
        If Err.Number <> 0 Then
            strError = Err.Source & ", " & Err.Description
        Else
            strError = ""
        End If
          
        On Error GoTo ErrorExit
        If strError <> "" Then
            ' 2011-03-16, JFW, Test to hold
            ' m_objShipment.Package.SendToHold
            
            Call m_objExcelBatch.AfterShipError(strError)
            
            ' 2011-08-12, JFW, ETD upload failure.
            Call PrintErrorLabel(m_objShipment.Package, strError)
            
            ' Logfile "formArrayBatch.BatchShipNext, Calling Cafe1.AfterShipment, with error, " & strError
            Call Cafe1.AfterShipment("")

            strTrackingNumber = ""
            
        ElseIf m_objShipment.MPS.Packages.Count > 0 Then
            For i = 0 To m_objShipment.MPS.Packages.Count - 1
                If strTrackingNumber = "" Then
                    strTrackingNumber = m_objShipment.MPS.Packages(i).TrackingNumber
                End If
            Next i
        
        ElseIf m_objShipment.Package.TrackNo <> "" Then
            strFreightCharge = ""
            strTrackingNumber = ""
            strTrackingNumber = m_objShipment.Package.TrackNo
            strFreightCharge = m_objShipment.Package.Charges.CustomerRates.NetCharge
        
            ' Logfile "formArrayBatch.BatchShipNext, After process, tracking number " & strTrackingNumber
            
        Else
            Call m_objExcelBatch.AfterShipError("BatchShipNext.Process, indeterminate transaction output.  No tracking number and no error message.  ")
            
        End If ' Error number
            
        If strTrackingNumber <> "" Then
            strTrackingNumberAll = ""
            strFreightCharge = "0"
            ' Lookup by master tracking number
            Set tblShipmentLookUp = Cafe2.Databases.ExecDirect("select 1123 from Shipment where 29 = '" & strTrackingNumber & "'")
            strTrackingNumber1 = tblShipmentLookUp.Records(0).Fields("1123").Value
            ' All packages
            Set tblShipmentLookUp = Cafe2.Databases.ExecDirect("select 29,37 from Shipment where 1123 = '" & strTrackingNumber1 & "' order by 29")
            For i = 0 To tblShipmentLookUp.Records.Count - 1
              ' ' Logfile "Tr " & tblShipmentLookUp.Records(i).Fields("29").Value & ", rate " & tblShipmentLookUp.Records(i).Fields("37").Value & "."
                If strTrackingNumberAll <> "" Then strTrackingNumberAll = strTrackingNumberAll & ", "
                strTrackingNumberAll = strTrackingNumberAll & tblShipmentLookUp.Records(i).Fields("29").Value
                strFreightCharge = CStr(CDec(strFreightCharge) + CDec(tblShipmentLookUp.Records(i).Fields("37").Value))
            Next i
        End If
        
        If strTrackingNumber1 <> "" Then
            
            If m_objExcelBatch.PackageCount > 1 _
            And Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
            
                If lngPackageCount = 0 Then
                    m_strSecondTrackingNumber = strTrackingNumber1
                End If
                
                ' 2009-07-24, JFW
                If m_objExcelBatch.PackageCount > 1 Then
                    modLabel8.m_boolTDMPSToggle = False
                    modLabel8.m_lngTDMPSPieceCount = lngPackageCount + 1
                    modLabel8.m_lngTDMPSTotalCount = m_objExcelBatch.PackageCount
                Else
                    modLabel8.m_boolTDMPSToggle = False
                    modLabel8.m_lngTDMPSPieceCount = 0
                    modLabel8.m_lngTDMPSTotalCount = 0
                End If
            End If
            
            ' 2009-07-24, JFW
            ' Logfile "ArrayBatch.BatchShipNext, Calling Cafe1.AfterShipment, tracking number " & strTrackingNumber1
            Call Cafe1.AfterShipment(strTrackingNumber1)

            ' Logfile "ArrayBatch.BatchShipNext, Calling Excel AfterShipment, tracking numbers " & strTrackingNumberAll
            Call m_objExcelBatch.AfterShip(strTrackingNumberAll, strFreightCharge)
            
            ' First piece of TD MPS
            If lngPackageCount = 0 _
            And m_objExcelBatch.PackageCount > 1 _
            And Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
                m_strSecondTrackingNumber = strTrackingNumber1
            End If

        End If
    
        lngPackageCount = lngPackageCount + 1
        Cafe1.g_boolAfterLabel = True
        If lngPackageCount >= m_objExcelBatch.PackageCount Then
            ' Logfile "ArrayBatch.BatchShipNext, end of TD MPS packages"
            Exit Do
        End If
        If m_objShipment.MPS.Packages.Count > 1 Then
            ' Logfile "ArrayBatch.BatchShipNext, end of MPS shipment"
            Exit Do
        End If
        If Not m_objShipment.Package.Intl.IncludeTD Then
            ' Logfile "ArrayBatch.BatchShipNext, end of single piece"
            Exit Do
        End If
        
    Loop ' Loop for each package in PackageCount, TD MPS
    
    BatchShipNext = True
    m_boolAfterShipment = True
    
    Debug.Print Now & " BatchShipNext, done " & m_lngShipmentCount

    Exit Function
    
ErrorFCIL:
    Err.Raise 12345, "ArrayBatch.BatchShipNext", "Error at TDPiece - Cannot access FCIL - Please report this to FedEx technical support.  " & Err.Source & " - " & Err.Description _
        , vbApplicationModal + vbSystemModal + vbExclamation
    Exit Function
ErrorFCILCurrentMaster:
    Err.Raise 12345, "ArrayBatch.BatchShipNext", "Error at TDPiece - Cannot access current master shipment.  Check the TD dashboard.  " & Err.Source & " - " & Err.Description _
        , vbApplicationModal + vbSystemModal + vbExclamation
    Exit Function
ErrorFCILReturnAddress:
    Err.Raise 12345, "ArrayBatch.BatchShipNext", "Error at TDPiece - Cannot access master shipment return address - Please report this to FedEx technical support.  " & Err.Source & " - " & Err.Description _
        , vbApplicationModal + vbSystemModal + vbExclamation
    Exit Function
ErrorExit:
    strError = Err.Source & ", " & Err.Description
    LogFile "ArrayBatch.BatchShipNext, Error " & strError
    m_boolAfterShipment = True
    Err.Raise 12345, "ArrayBatch.BatchShipNext", strError
    Resume
End Function


Public Function StartBatch(ByVal TrackingNumber As String) As Boolean

    On Error GoTo ErrorExit
    
    Dim i As Long
    Dim aHandle As Long
    Dim strError As String
    
    '+
    ' Get Net charge for the first shipment of the batch
    Dim strNetCharge As String
    Dim tblShipmentLookUp As Table
    Dim strTrackingNumber As String
    ' Lookup by master tracking number
    Set tblShipmentLookUp = Cafe2.Databases.ExecDirect("select 1123 from Shipment where 29 = '" & TrackingNumber & "'")
    TrackingNumber = tblShipmentLookUp.Records(0).Fields("1123").Value
    ' 2009-07-24, JFW
    m_strFirstTrackingNumber = TrackingNumber
    m_strSecondTrackingNumber = TrackingNumber
    
    Set tblShipmentLookUp = Cafe2.Databases.ExecDirect("select 29,37 from Shipment where 1123 = '" & TrackingNumber & "' order by 29")
    For i = 0 To tblShipmentLookUp.Records.Count - 1
      ' ' Logfile "Tr " & tblShipmentLookUp.Records(i).Fields("29").Value & ", rate " & tblShipmentLookUp.Records(i).Fields("37").Value & "."
        
        If strTrackingNumber <> "" Then strTrackingNumber = strTrackingNumber & ", "
        strTrackingNumber = strTrackingNumber & tblShipmentLookUp.Records(i).Fields("29").Value
        If strNetCharge = "" Then strNetCharge = "0"
        strNetCharge = CStr(CDec(strNetCharge) + CDec(tblShipmentLookUp.Records(i).Fields("37").Value))
    Next i
    '~
    ' 2009-07-24, JFW
    If m_objExcelBatch.PackageCount > 1 Then
        modLabel8.m_boolTDMPSToggle = False
        modLabel8.m_lngTDMPSPieceCount = 1
        modLabel8.m_lngTDMPSTotalCount = m_objExcelBatch.PackageCount
    Else
        modLabel8.m_boolTDMPSToggle = False
        modLabel8.m_lngTDMPSPieceCount = 0
        modLabel8.m_lngTDMPSTotalCount = 0
    End If
    ' Logfile "ArrayBatch.StartBatch, Set up m_lngTDMPSPieceCount " & m_lngTDMPSTotalCount
    ' Logfile "ArrayBatch.StartBatch, Calling Cafe1.AfterShipment, tracking number " & TrackingNumber
    Call Cafe1.AfterShipment(TrackingNumber)
        
    Call m_objExcelBatch.AfterShip(strTrackingNumber, strNetCharge)
    
    If m_fcilPackageXML Is Nothing Then
        Set m_fcilPackageXML = New PackageXML
    End If
    Set m_objXML = m_fcilPackageXML.AfterShipXMLRequest(TrackingNumber)
    
    ' Logfile "Start batch, shipment XML ..."
    ' Logfile m_objXML.XML
    
    ' Need an empty Shipment object
    Set m_objShipment = New Shipment
    ' Create a package from an XML document
    Set m_objPackage = m_fcilPackageXML.ShipXMLMPS(m_objShipment, m_objXML)
    
    '' Logfile "Docs", m_objPackage.Intl.Docs.Count
    
    If m_objShipment.MPS.Packages.Count > 1 Then
        ' Logfile "StartBatch, Package1 weight " & m_objShipment.MPS.Packages(0).Weight
        ' Logfile "StartBatch, Package1 dims length " & m_objShipment.MPS.Packages(0).Length
    Else
        ' Logfile "StartBatch, Shipment weight " & m_objShipment.Package.Weight
        ' Logfile "StartBatch, Package dims length " & m_objShipment.Package.Dimensions.Length
    End If
    
    ' Set focus to TD Packaging
    Window.Restore Window.Find("Array Batch Process")
    aHandle = Window.SetTopMost(Me)
    Call Window.SetFocus(aHandle)
        
    StartBatch = True
    m_lngShipmentCount = 0
    
    If timerTDB Is Nothing Then Set timerTDB = New Timer
    timerTDB.Interval = 500 ' 1000
    timerTDB.Enabled = True
    Cafe1.g_boolAfterLabel = True
    m_boolAfterShipment = True
    Exit Function
    
ErrorExit:
    strError = Err.Source & ", " & Err.Description
    LogFile "ArrayBatch.StartBatch, Error " & strError
    Err.Raise 12345, "ArrayBatch.StartBatch", strError
    Resume
End Function


Public Sub StopTD()

    ' On Error Resume Next
    
    timerTDB.Enabled = False
    Set g_formArrayBatch = Nothing
    Set m_objExcelBatch = Nothing
    Unload Me
    
End Sub


Private Sub buttonBrowse_Click()

    cdlSave.FileName = "*.xls"
    cdlSave.Filter = "Excel workbook (*.xls)|*.xls|"
    cdlSave.ShowOpen
    
    textFilename = cdlSave.FileName
    
End Sub


Private Sub buttonShip_Click()

    On Error GoTo ErrorExit
    
    Dim objPackage As Package
    Dim objShipment As Shipment
    Set objShipment = New Shipment
    
    If textFilename = "" Then Exit Sub
    
    Set m_objExcelBatch = New classExcelBatch
    
    m_objExcelBatch.ExcelImport (textFilename)
    
    Set objShipment = New Shipment
    Set objPackage = objShipment.Package
    
    If m_objExcelBatch.ShipNext(objShipment) Then
        objShipment.MPS.WeightType = fsmLbs
        objPackage.WeightType = fsmLbs
                
'        If Not m_objExcelBatch.ShipDims(0) Is Nothing Then
'            objPackage.Dimensions.Length = CDbl(m_objExcelBatch.ShipDims(0).Item(1))
'            objPackage.Dimensions.Width = CDbl(m_objExcelBatch.ShipDims(0).Item(2))
'            objPackage.Dimensions.Height = CDbl(m_objExcelBatch.ShipDims(0).Item(3))
'        End If
        
        ' 2011-11-10, JFW, Let Ground be the default Array service.
        If True _
        Or 0 <> InStr(1, UCase(Me.textFilename), "COTY") _
        Or 0 <> InStr(1, UCase(Me.textFilename), "WALGR") Then
            objShipment.MPS.ServiceType = fsmGround
            objPackage.ServiceType = fsmGround
        Else
            objShipment.MPS.ServiceType = 1
            objPackage.ServiceType = 1
        End If
        objShipment.MPS.PackageType = 1
        objPackage.PackageType = 1
        objShipment.MPS.International.PackageType = fsmFedEx_Intl_Box
        objPackage.Intl.PackageType = fsmFedEx_Intl_Box
        
        If Me.checkTD.Value And m_objExcelBatch.IncludeTD Then
            
            ' Logfile "ArrayBatch, Ship, Intl TD"
            
            objPackage.Intl.IncludeTD = True
        
            If m_objExcelBatch.PackageCount > 1 Then
                modLabel8.m_boolTDMPSToggle = False
                modLabel8.m_lngTDMPSPieceCount = 1
                modLabel8.m_lngTDMPSTotalCount = m_objExcelBatch.PackageCount
            End If
        
        ElseIf objPackage.Recipient.Country <> "CA" Then
            With objShipment.MPS.International
                .PackageType = fsmFedEx_Intl_Box
                ' Logfile "ArrayBatch, Ship, 1 pc, Intl UploadTrade"
                .IncludeTD = False
                .UploadTradeDocumentsFlag = True
                .IncludeCommercialInvoice = True
                .CommercialInvoice.Copies = 0
                If .Commodities.Count <= 0 Then
                    With .CommercialInvoice
                        .InvoiceType = fsmCommercialInvoice
                        .Copies = 0
                        .InvoicePurpose = fsmSold
                    End With
                Else
                    With .CommercialInvoice
                        .InvoiceType = fsmMyOwnCommercialInvoice
                        .Copies = 0
                        .InvoicePurpose = fsmSold
                        .InvoicePath = Cafe4.CreateShipmentCI(objShipment)
                    End With
                End If
            End With
            With objShipment.Package.Intl
                .PackageType = fsmFedEx_Intl_Box
                ' Logfile "ArrayBatch, Ship, 1 pc, Intl UploadTrade"
                .IncludeTD = False
                .UploadTradeDocumentsFlag = True
                .IncludeCommercialInvoice = True
                .CommercialInvoice.Copies = 0
                If .Commodities.Count <= 0 Then
                    With .CommercialInvoice
                        .InvoiceType = fsmCommercialInvoice
                        .Copies = 0
                        .InvoicePurpose = fsmSold
                    End With
                ElseIf False Then
                    With .CommercialInvoice
                        .InvoiceType = fsmCommercialInvoice
                        .Copies = 1
                        .InvoicePurpose = fsmSold
                    End With
                Else
                    With .CommercialInvoice
                        .InvoiceType = fsmMyOwnCommercialInvoice
                        .Copies = 0
                        .InvoicePurpose = fsmSold
                        .InvoicePath = Cafe4.CreatePackageCI(objShipment.Package)
                    End With
                End If
            End With
            
        End If
        
        If objShipment.MPS.Packages.Count > 1 Then
            objShipment.MPS.SendToScreen
            Breathe
            Cafe2.Screen.Clear
            Breathe
            objShipment.MPS.SendToScreen
            Breathe
        Else
            objShipment.Package.SendToScreen
            Breathe
            Cafe2.Screen.Clear
            Breathe
            objShipment.Package.SendToScreen
            Breathe
        End If
    End If
    
    Window.Flash Window.Find("Array Batch Process")
    Window.Minimize Window.Find("Array Batch Process")
    
    Window.SetFocus Window.Find("FedEx Ship")
    
    Exit Sub
    
ErrorExit:
    MsgBox "Error - " & Err.Source & " - " & Err.Description, vbApplicationModal + vbSystemModal
    Set m_objExcelBatch = Nothing
    If False Then
        Resume
    End If
End Sub


Private Sub timerTDB_Execute()

    On Error GoTo ErrorExit
    Dim strError As String
    
    ' Logfile "ArrayBatch.timerTDB_Execute, AfterLabel " & Cafe1.g_boolAfterLabel & ", AfterShipment " & m_boolAfterShipment
    
    If (Cafe1.g_boolAfterLabel And m_boolAfterShipment) _
    Or Now > DateAdd("s", 25, g_dtAfterShipment) Then
        g_dtAfterShipment = Now
        Cafe1.g_boolAfterLabel = False
        m_boolAfterShipment = False
        
        If BatchShipNext Then
            timerTDB.Enabled = True
        Else
            timerTDB.Enabled = False
            ' Logfile "ArrayBatch, Complete " & m_objExcelBatch.CountTotal & " records, " & m_objExcelBatch.CountError & " in error."
            Me.textStatus = "Complete " & m_objExcelBatch.CountTotal & " records, " & m_objExcelBatch.CountError & " in error."
            Set m_objExcelBatch = Nothing
            Exit Sub
        End If
    End If
    Exit Sub
    
ErrorExit:
    strError = Err.Source & ", " & Err.Description
    LogFile "ArrayBatch.TDB, Error - " & strError, vbApplicationModal + vbSystemModal
    MsgBox "ArrayBatch.TDB, Error - " & strError, vbApplicationModal + vbSystemModal
    Set m_objExcelBatch = Nothing
    If False Then
        Resume
    End If
    
End Sub

Private Sub timerTest_Execute()

    On Error GoTo ErrorExit

    timerTest.Enabled = False
    
    checkTD.Value = False
    textFilename.Text = "C:\Program Files\FedEx\Integration\Projects\Array\Data Files\P20558 Bliss Test.xls"
    
    'checkTD.Value = True
    'textFilename.Text = "C:\Program Files\FedEx\Integration\Projects\Array\P19578 Coty Walgreen 5400 Direct Doors.xls"
    
    Call buttonShip_Click

    Exit Sub
    
ErrorExit:
    MsgBox "Error - " & Err.Source & " - " & Err.Description, vbApplicationModal + vbSystemModal
    Set m_objExcelBatch = Nothing

End Sub

Private Sub UserForm_Initialize()
    
    Dim i As Long
    
    Dim objReg As FSIX.IRegistry
    Set objReg = New FSIX.IRegistry
    
    checkTD.Value = True
    
    If Windows.ComputerName = "CAN-00278478" Then
        Set timerTest = New Timer
        timerTest.Interval = 1000
        timerTest.Enabled = True
    End If
    
    ' frameHoldEdit.Visible = False
    
    ' Me.Left = objReg.GetValue(fsiDefault, "HoldFileList", "Left")
    ' Me.Top = objReg.GetValue(fsiDefault, "HoldFileList", "Top")
    
End Sub

Private Sub UserForm_Terminate()

    On Error Resume Next
    
    Dim objReg As FSIX.IRegistry
    Set objReg = New FSIX.IRegistry

    Set g_formArrayBatch = Nothing
    
    ' objReg.SaveValue "HoldFileList", "Left", Me.Left
    ' objReg.SaveValue "HoldFileList", "Top", Me.Top

End Sub
